package com.wc.AlgoOJ_homework.AlgoOJ_BL3.F_翻转括号序列;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/4/4 12:34
 * @description http://43.138.190.70:8888/p/511?tid=6602a77318e03a818a4bf04e
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 100010;
    static char[] s = new char[N];
    static int[] a = new int[N];
    static int top;
    static int n, m, l, r, x;

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        s = (" " + sc.next()).toCharArray();
        for (int i = 1; i <= n; i++) {
            if (s[i] == '(') a[i] = 1;
            else a[i] = 0;
        }
        while (m-- > 0) {
            x = sc.nextInt();
            l = sc.nextInt();
            if (x == 1) {
                r = sc.nextInt();
                for (int i = l; i <= r; i++) a[i] ^= 1;
            } else {
                int res = 0;
                if (a[l] == 0) {
                    out.println(0);
                    continue;
                }
                top = 1;
                r = l + 1;
                while (r <= n) {
                    if (a[r] == 0) {
                        if (top >= 1) {
                            top--;
                        } else {
                            break;
                        }
                    } else if (a[r] == 1) {
                        top++;
                    }
                    if (top == 0) res = r;
                    r++;
                }
                out.println(res);
            }
        }
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}